import { ref, getCurrentInstance, onMounted } from 'vue'
export const useEcharts = (props?: any, initData?: any, emit?: any) => {
  const ctx: any = getCurrentInstance()?.appContext.config.globalProperties
  const myChart = ref<HTMLElement>()
  const myCharts = ref<any>()
  onMounted(() => {
    initEcharts()
  })
  const initEcharts = () => {
    console.log('echarts')
    myCharts.value = ctx.$echarts.init(myChart.value!)
    myCharts.value.setOption({
      title: { text: '总用户量' },
      tooltip: {},
      xAxis: {
        data: ['12-3', '12-4', '12-5', '12-6', '12-7', '12-8'],
      },
      yAxis: {},
      series: [
        {
          name: '用户量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20],
        },
      ],
    })
  }

  return {
    initEcharts,
    myChart
  }
}
